<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="checkbox" class="check">
    <input type="checkbox" class="checkItem">
    <input type="checkbox" class="checkItem">
    <input type="checkbox" class="checkItem">
    <input type="checkbox" class="checkItem">
<script>
    const check =document.querySelector(".check")
    const checkAll=document.querySelectorAll(".checkItem")

    check.addEventListener("change",function(e){
        let isAllChecked=e.target.checked
         checkAll.forEach((item)=>{
            item.checked=isAllChecked
         })
    })

    checkAll.forEach((item)=>{
        item.addEventListener("change",function () {
            if (document.querySelectorAll(".checkItem:checked").length===checkAll.length) {
                check.checked=true
            }else{
                check.checked=false

            }
        })
    })

</script>
</body>
</html>